package com.qidian.mes.pro.controller;

import com.qidian.mes.pojo.pro.ProWorkorder;
import com.qidian.mes.pro.service.ProWorkorderService;
import com.qidian.mes.util.pojo.MESResult;
import netscape.javascript.JSObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author 郭靖旖
 * @Company
 * @Time 2023/10/26 14:43
 * @Description
 **/
@RestController
@RequestMapping("/wororder")
@CrossOrigin
public class ProWorkorderController {
    @Autowired
    ProWorkorderService proWorkorderService;
    //按条件分页查询
    @GetMapping ("/list")
    public MESResult list(@RequestParam(defaultValue = "1")int page , @RequestParam(defaultValue ="10") int limit,ProWorkorder proWorkorder){
        System.err.println(proWorkorder);
        return proWorkorderService.list(page,limit,proWorkorder);
    }
    //分页总查询
    @GetMapping("/get")
    public MESResult get(@RequestParam(defaultValue = "1")int page , @RequestParam(defaultValue ="10") int limit){
        return proWorkorderService.selectByPage(page,limit);
    }
    //自动生成工单编号
@RequestMapping("/GenerateAWorkOrder")
    public MESResult GenerateAWorkOrder(){
        return proWorkorderService.GenerateTheWorkOrderNumber();
}

//新增数据
    @PostMapping("/save")
    public MESResult save(@RequestBody ProWorkorder proWorkorder){
        System.err.println(proWorkorder.getStatus());
        if (proWorkorder.getOrderSource().equals("2")) {
            proWorkorder.setOrderSource("库存备货");
        }
        else {
            proWorkorder.setOrderSource("客户订单");
        }
        return proWorkorderService.save(proWorkorder);
    }
    //修改工单状态
    @GetMapping("/updateStatus")
    public MESResult updateStatus( String workorderCode){
        return proWorkorderService.updateStatus(workorderCode);
    }
    //删除工单
    @DeleteMapping("/deleteWorkorder")
    public MESResult deleteWorkorder(String workorderCode){
        return proWorkorderService.deleteWorkorder(workorderCode);
    }
}
